package com.xy.service.mqtt.impl;

import com.xy.api.model.dto.mqtt.MqttDTO;
import com.xy.service.mqtt.IMqttService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;

@Slf4j
@Service
public class MqttServiceImpl implements IMqttService {

    public MqttDTO appGet(String clientId) {
        UAP uap = mqttUAP();
        MqttDTO mqttDTO = save(clientId, uap.username, uap.password);
        return mqttDTO;
    }

    public MqttDTO save(String eid, String userName, String password) {
        // 将eid、userNam、password保存在数据库
        MqttDTO mqttDTO = new MqttDTO();
        mqttDTO.setEid(eid);
        mqttDTO.setUsername(userName);
        mqttDTO.setPassword(password);
        return mqttDTO;
    }

    public static UAP mqttUAP() {
        String username = "admin";
        String password = "admin";
        return new UAP(username, password);
    }

    public static class UAP {
        public final String username;
        public final String password;

        public UAP(String username, String password) {
            this.username = username;
            this.password = password;
        }
    }
}
